﻿using Microsoft.AspNetCore.Authorization;

namespace SageKing.Blazor.OpenIdService.Services;

public class PermissionHandler : IAuthorizationHandler
{
    public Task HandleAsync(AuthorizationHandlerContext context)
    {
        //foreach (var req in context.Requirements.OfType<Authorize>())
        //{
        //    if (context.User.HasClaim("Permission", req.Permission))
        //        context.Succeed(req);
        //}
        //var authState = authenticationState.GetAuthenticationStateAsync().Result;

        var dd = context.User;
        return Task.CompletedTask;
    }
}

public class MultiRequirementHandler : IAuthorizationHandler
{
    public Task HandleAsync(AuthorizationHandlerContext context)
    {
        var dd = context.User;

        //foreach (var req in context.Requirements)
        //{
        //    if (req is AgeRequirement ageReq && CheckAge(context.User, ageReq.MinAge))
        //        context.Succeed(ageReq);
        //    if (req is RoleRequirement roleReq && CheckRole(context.User, roleReq.Role))
        //        context.Succeed(roleReq);
        //}
        return Task.CompletedTask;
    }
}